package cn.wind.xboot.framework.oauth;

import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * <p>Title: OauthDao</p>
 * <p>Description: TODO</p>
 *
 * @author xukk
 * @version 1.0
 * @date 2018/8/24
 */
@Service
public class OauthDao extends JdbcDaoSupport {
    @Resource
    private DataSource dataSource;

    @PostConstruct
    private void initialize() {
        setDataSource(dataSource);
    }

    public Integer getRefreshTokenExpiredTime() {
        Integer expiredTime = getJdbcTemplate().
                queryForObject("select refresh_token_validity from oauth_client_details where client_id=? and scope=?",
                        new Object[]{"back", "back"}, (rs, rowNum) -> rs.getInt("refresh_token_validity"));

        if (expiredTime != null) {
            return expiredTime;
        } else {
            return 30*24*3600;
        }

    }
}
